﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class FriendDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.FriendDetails_PageTitle;
            // security part
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");

            OnlineUser ou = (OnlineUser)Session["User"];

            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();

            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");
            
            // removed  - this page will be available for non premium users too.
            // if (!ou.IsPremium)
            //    Response.Redirect("~/GeneralMessage.aspx?MessageString=gfkkjFSDei3w7lzTD");

            if (Request.QueryString["Id"] == null)
                Response.Redirect("~/Friends.aspx");
            else
            {
                FriendIdHiddenField.Value = Request.QueryString["Id"];
            }

            if (!GND.ReadNivdalBoolData("User1", "User2", "Nivdal_FriendshipAreUsersFriendsProc", ou.UserId, FriendIdHiddenField.Value))
                Response.Redirect("~/Friends.aspx");

            string FriendName = GND.ReadNivdalStringData("UserId", "Nivdal_GetUserNameById", FriendIdHiddenField.Value);
            Title = Resources.Resource.FriendDetails_FriendDetails + " " + FriendName + " - Nivdal.com!";
            PageNameLabel.Text = Resources.Resource.Global_Friends + ">>" + " " + FriendName + Resources.Resource.Global_Details;
            this.FriendDetailsTitleLabel.Text = Resources.Resource.FriendDetails_FriendDetailsTitleLabelText + " " + FriendName;

            if (!IsPostBack)
            {
                this.FriendDetailsSqlSourse.SelectParameters.Add("FriendId", FriendIdHiddenField.Value);
                this.FriendDetailsSqlSourse.SelectParameters.Add("FriendOf", ou.UserId);
                string FriendTeamIs = GND.ReadNivdalIntData("@UserId", "Nivdal_GetTeamIdByUserId", FriendIdHiddenField.Value);
                this.MatchesSqlSourse.SelectParameters.Add("TeamId", FriendTeamIs);
                //this.InjuredWarnedPlayersDataSourse.SelectParameters.Add("TeamId", FriendTeamIs);
                this.TransfersSqlDataSourse.SelectParameters.Add("TeamId", FriendTeamIs);
            }
        }

        protected void StopFriendship(object sender, EventArgs e)
        {
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            OnlineUser ou = (OnlineUser)Session["User"];
            string SuggestionId = GND.ReadNivdalStringData("Friend1", "Friend2", "Nivdal_FriendsGetSuggestionIdFor2Friends", ou.UserId, this.FriendIdHiddenField.Value);
            string Asnwer = GND.ReadNivdalStringData("SuggestionId", "Language", "Nivdal_FriendshipStopBeingFriends", SuggestionId, ou.Language);
            string FriendName = GND.ReadNivdalStringData("UserId", "Nivdal_GetUserNameById", FriendIdHiddenField.Value);
            Response.Redirect("~/Friends.aspx?Message=" + FriendName + " " + Resources.Resource.FriendDetails_IsNotYourFriendAnyMoreMessageText);
        }

        //protected string GetIconByMatchType(object o)
        //{
        //    string ReturnValue = "~/Images/Icons/";
        //    string Type = o.ToString();

        //    switch (Type)
        //    {
        //        case "1":
        //            ReturnValue += "LeagueIcon.png";
        //            break;
        //        case "2":
        //            ReturnValue += "NationalCupIcon.png";
        //            break;
        //        case "3":
        //            ReturnValue += "InternationalCupIcon.png";
        //            break;
        //        default:
        //            ReturnValue += "FriendlyIcon.png";
        //            break;
        //    }
        //    return (ReturnValue);
        //}

        

        protected bool WarningCardVisible(decimal Warnings, int CardNum)
        {
            bool ReturnValue = false;

            if ((CardNum == 1) && ((Warnings == 1) || (Warnings == 2)) ||
                ((CardNum == 2) && (Warnings == 2)) ||
                ((CardNum == 3) && (Warnings >= 3)))
                ReturnValue = true;

            return (ReturnValue);
        }

        protected override void InitializeCulture()
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }

    }
}